<template>
  <div>
    <!-- 查询框 -->
    <van-search
      v-model="value"
      show-action
      background="#4fc08d"
      placeholder="请输入搜索关键词"
      @click-left="$router.go(-1)"
    >
      <!-- 外部 -->
      <template #left>
        <van-icon name="arrow-left" color="#fff" size="16" />
      </template>
      <template #action>
        <van-icon
          name="location-o"
          size="20"
          color="#fff"
          @click="$router.push('/map')"
        />
      </template>
      <!-- 内部 -->
      <template #label>
        <router-link to="/city">{{ city.label }}</router-link>
      </template>
    </van-search>

    <!-- 筛选 -->
    <van-sticky>
      <van-dropdown-menu active-color="#4fc08d">
        <van-dropdown-item title="区域">
          <van-picker
            show-toolbar
            :columns="columns"
            toolbar-position="bottom"
          />
        </van-dropdown-item>
        <van-dropdown-item title="方式">
          <van-picker
            show-toolbar
            :columns="columns"
            toolbar-position="bottom"
          />
        </van-dropdown-item>
        <van-dropdown-item title="租金">
          <van-picker show-toolbar :columns="rent" toolbar-position="bottom" />
        </van-dropdown-item>
        <van-dropdown-item title="筛选" @open="show = true"></van-dropdown-item>
      </van-dropdown-menu>
    </van-sticky>

    <!-- 弹出层 -->
    <van-popup
      v-model="show"
      position="right"
      :style="{ height: '100%', width: '80%' }"
    >
      <ul>
        <li>
          <div class="sun_filter_popup_title">户型</div>
          <div class="sun_filter_popup_buttons">
            <ul class="ul_style">
              <li>
                <button>一室</button>
                <button>二室</button>
              </li>
              <li>
                <button>三室</button>
                <button>四室</button>
              </li>
              <li>
                <button>四室+</button>
              </li>
            </ul>
            <div class="line"></div>
          </div>
        </li>
        <li>
          <div class="sun_filter_popup_title">朝向</div>
          <div class="sun_filter_popup_buttons">
            <ul class="ul_style">
              <li>
                <button>东</button>
                <button>西</button>
              </li>
              <li>
                <button>南</button>
                <button>北</button>
              </li>
              <li>
                <button>东南</button>
                <button>东北</button>
              </li>
              <li>
                <button>西南</button>
                <button>西北</button>
              </li>
            </ul>
            <div class="line"></div>
          </div>
        </li>
        <li>
          <div class="sun_filter_popup_title">楼层</div>
          <div class="sun_filter_popup_buttons">
            <ul class="ul_style">
              <li>
                <button>高楼层</button>
                <button>中楼层</button>
              </li>
              <li>
                <button>低楼层</button>
              </li>
            </ul>
            <div class="line"></div>
          </div>
        </li>
        <li style="margin-bottom: 80px">
          <div class="sun_filter_popup_title">房屋亮点</div>
          <div class="sun_filter_popup_buttons">
            <ul class="ul_style">
              <li>
                <button>集中供暖</button>
                <button>双卫生间</button>
              </li>
              <li>
                <button>近地铁</button>
                <button>随时看屏</button>
              </li>
              <li>
                <button>精装</button>
                <button>公寓</button>
              </li>
              <li>
                <button>独立卫生间</button>
                <button>押一付一</button>
              </li>
              <li>
                <button>独立阳台</button>
                <button>月租</button>
              </li>
              <li>
                <button>限女生</button>
                <button>限男生</button>
              </li>
              <li>
                <button>新上</button>
              </li>
            </ul>
          </div>
        </li>
      </ul>
      <div class="btn">
        <span>清除</span>
        <span>确定</span>
      </div>
    </van-popup>

    <!-- 渲染页面 -->
    <div class="sum_render_list">
      <ul>
        <li
          v-for="(item, index) in housesList"
          :key="index"
          @click="$router.push(`/details/${item.houseCode}`)"
        >
          <div class="pic">
            <van-image
              width="106"
              height="80"
              lazy-load
              :src="'http://liufusong.top:8080' + item.houseImg"
            />
          </div>
          <div class="txt">
            <h3>{{ item.title }}</h3>
            <span>{{ item.desc }}</span>
            <p>{{ item.tags[0] }}</p>
            <div class="price">
              <span>{{ item.price }}</span
              >元/月
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
// 根据条件查询房屋
import { queryHouses } from '@/api/sun'
import { cityInfo } from '@/api/city'
export default {
  name: 'sun-page',

  data() {
    return {
      value: null,
      housesList: [],
      city: JSON.parse(localStorage.getItem('city')) || {
        label: '上海',
        pinyin: 'shanghai',
        short: 'sh',
        value: 'AREA|dbf46d32-7e76-1196'
      },
      columns: ['杭州', '宁波', '温州', '绍兴', '湖州', '嘉兴', '金华', '衢州'],
      rent: [],
      show: false
    }
  },
  async created() {
    // 根据城市名称查询该城市信息
    const res2 = await cityInfo(this.city.label)
    const res = await queryHouses(res2.body.value)
    this.housesList = res.body.list

    // 筛选租金
  },
  methods: {},
  computed: {},
  watch: {}
}
</script>

<style scoped lang="less">
// 查询框
.van-search {
  ::v-deep .van-search__action {
    transform: translateY(-2px);
  }
  .van-search__content {
    background-color: #fff;
  }
  .van-icon-arrow-left:before {
    margin-right: 10px;
  }
  .van-icon-location-o:before {
    transform: translateY(4px);
    margin-right: 4px;
  }
  .van-search__label:after {
    content: '';
    display: inline-block;
    margin-left: 14px;
    transform: translateY(4px);
    width: 1px;
    height: 16px;
    background-color: rgba(0, 0, 0, 0.2);
  }
}

// 渲染页面
.sum_render_list {
  ul {
    li {
      padding: 20px 15px;
      border-bottom: 1px solid #e5e5e5;
      display: flex;
      .txt {
        margin-left: 12px;
        h3 {
          font-size: 15px;
          color: #394043;
        }
        span {
          font-size: 12px;
          color: #afb2b3;
        }
        p {
          margin-top: 4px;
          width: 46px;
          height: 20px;
          background-color: #e1f5f8;
          text-align: center;
          line-height: 20px;
          color: #fff;
          font-size: 12px;
          color: #39becd;
        }
        .price {
          margin-top: 4px;
          span {
            font-size: 16px;
            color: #fa5741;
            font-weight: 700;
            margin-right: 4px;
          }
          font-size: 12px;
          color: #fa5741;
        }
      }
    }
  }
}

// 下拉菜单
.van-dropdown-menu {
  ::v-deep .van-dropdown-menu__bar {
    height: 40px;
  }
  ::v-deep .van-ellipsis {
    font-size: 17px;
    color: #333;
  }
}

// 按钮
::v-deep .van-picker__toolbar {
  height: 50px;
  border-top: 1px solid #e9e9e9;
}
::v-deep .van-picker__cancel {
  width: 125px;
  background-color: #fff;
  color: #21b97a;
  font-size: 18px;
}
::v-deep .van-picker__confirm {
  width: 250px;
  background-color: #21b97a;
  color: #fff;
  font-size: 18px;
}

// 弹出框
.van-popup {
  .sun_filter_popup_title {
    font-size: 15px;
    color: #333;
    margin: 18px 0 18px 14px;
  }
  button {
    display: inline-block;
    margin-right: 16px;
    margin-bottom: 16px;
    width: 70px;
    height: 32px;
    font-size: 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background-color: transparent;
  }
  .ul_style {
    margin-left: 50px;
  }
  .line {
    width: 245px;
    height: 1px;
    background-color: #e5e5e5;
    margin-top: 14px;
    margin-left: 50px;
  }

  // 按钮
  .btn {
    border-top: 1px solid #e5e5e5;
    height: 50px;
    line-height: 50px;
    text-align: center;
    span:first-child {
      display: inline-block;
      width: 30%;
      background-color: #fff;
    }
    span:last-child {
      display: inline-block;
      width: 70%;
      background-color: #21b97a;
      color: #fff;
      font-size: 18px;
    }
  }
}
</style>
